package org.opu.vcforms.template;

import java.util.Arrays;

/**
 *
 * @author yura
 */
public class Validator {

    public static <T> boolean isOneOf(T value, T... etalonSet){
        for (Object object : etalonSet) {
            if(value.equals(object)){
                return true;
            }
        }

        return false;
    }

    public static <T> void assertIsOneOf(String msg, T value, T... etalonSet)
            throws IllegalArgumentException{
        if (!isOneOf(value, etalonSet)){
            throw new IllegalArgumentException(msg + ". Value is '" + value
                    + "', but expected value must be one of '" 
                    + Arrays.toString(etalonSet) + "'");
        }
    }

    public static <T> void assertIsEquals(String msg, T value, T etalon)
            throws IllegalArgumentException{
        if (!etalon.equals(value)) {
            throw new IllegalArgumentException(msg);
        }
    }

}
